package com.maybach.common.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by houenxun on 16/1/18.
 */
public enum PartnerStatusEnum {
    disable(2, "禁用"),
    normal(1, "正常"),
    logical_delete(-1, "已删除"),
    wait_audit(0, "待审核");


    private int code;
    private String desc;


    private PartnerStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }


    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据状态code 获取状态值
     *
     * @param code
     * @return
     */
    public static PartnerStatusEnum getStatus(int code) {
        for (PartnerStatusEnum status : PartnerStatusEnum.values()) {
            if (code == status.code) {
                return status;
            }
        }
        return null;
    }

    /**
     * 根据状态code 获取状态列表
     *
     * @param code
     * @return
     */
    public static List<PartnerStatusEnum> getStatusList(int code) {
        List<PartnerStatusEnum> list = new ArrayList<>();
        for (PartnerStatusEnum status : PartnerStatusEnum.values()) {
            if ((code & status.code) == status.code) {
                list.add(status);
            }
        }
        return list;
    }

    public static String getDescByCode(int code) {
        for (PartnerStatusEnum partnerStatusEnum : PartnerStatusEnum.values()) {
            if (code == partnerStatusEnum.code) {
                return partnerStatusEnum.desc;
            }
        }
        return null;
    }
}
